<!DOCTYPE html>
<html>
<head>
    <title></title>
</head>
<body>
<script>
/*   function father(name){
    this.name = name;
   }
   father.prototype.getName = function(){
    return this.name;
   }

   function son(name,age){
    father.call(this,name);
    this.age = age;
   }
   son.prototype = new father();

   var son1 = new son("haha",12);
   console.log(son1.name+ " " + son1.age); //haha 12
   console.log(son1.getName()); //haha

//----------------------------------
   function obj(o){
    function F(){}
    F.prototype = o;
    return new F();
   }

   var father = {
    name: "baba",
    age: 50,
    colors: ['red','blue','yellow'],
    getName: function(){
        return this.name;
    }
   }

   console.log(father.getName());  //baba
   var son = obj(father);
   console.log(son.name+" "+son.age);//baba 50
   console.log(son.getName());  //baba

   son.name = "Jack";
   console.log(son.name);//Jack
   console.log(son.__proto__.name);//baba

   son.colors.push("black");
   console.log(son.colors);//["red", "blue", "yellow", "black"] 
   console.log(son.__proto__.colors);//["red", "blue", "yellow", "black"] 

//----------------------------------


   function obj(o){
    function F(){}
    F.prototype = o;
    return new F();
   }

   function create(o){
    var f = obj(o);
    f.getColors = function(){
        return this.colors;
    }
    return f;
   }

   var father = {
    name: "baba",
    age: 50,
    colors: ['red','blue','yellow'],
    getName: function(){
        return this.name;
    }
   }

  
   var son2 = create(father);
   son2.colors.push("black");
   console.log(son2.colors);//["red", "blue", "yellow", "black"] 
   console.log(son2.__proto__.colors);//["red", "blue", "yellow", "black"] 
   console.log(father.colors);//["red", "blue", "yellow", "black"] 

   var son3 = create(father);
   console.log(son3.colors);
   console.log(son3.getColors());
   */


   function obj(o){
    function F(){}
    F.prototype = o;
    return new F();
   }

   function create(Father,Son){
    var f = obj(Father.prototype);
    f.constructor = Son;
    Son.prototype = f; 
   }

   function Father(name){
    this.name = name;
    this.colors = ['red','blue','yellow'];
   }
   Father.prototype.run = function(){
    return this.name +" "+this.colors;
   }

   function Son(name,age){
    Father.call(this,name);
    this.age = age;
   }
   create(Father,Son);  //通过这里实现继承

   var son = new Son("xx",5);
   son.colors.push("pink");
   console.log(son.colors); //["red", "blue", "yellow", "pink"] 
   console.log(son.run());  //xx red,blue,yellow,pink 

   var son2 = new Son("xxoo",7);
   son.colors.push("green");
   console.log(son2.colors); //["red", "blue", "yellow"]
   console.log(son2.run());  //xxoo red,blue,yellow 
</script>
</body>
</html>